#include "p_queue.h"
#include "stdio.h"

#define TAG "MAIN: "
#define p_queue_debug_log(TAG, ...) do{printf("%s", TAG); printf(__VA_ARGS__); printf("\n");} while(0)
#define p_queue_info_log(TAG, ...)  do{printf("%s", TAG); printf(__VA_ARGS__); printf("\n");} while(0)


int main() {
    p_queue_t *pq = p_queue_create(3, 10, sizeof(int));  // 最大队列大小为10，优先级数量为3，数据类型大小为4字节

    if (!pq) {
        p_queue_debug_log(TAG, "Failed to create priority queue.");
        return -1;
    }

    int data0 = 0, data1 = 1, data2 = 2, data3 = 3;

    for (int i = 0; i < 10; i++) {
        p_queue_send(pq, &data2, 2);  // 数据: 2，优先级: 2
        p_queue_send(pq, &data1, 1);  // 数据: 1，优先级: 1
        p_queue_send(pq, &data0, 0);  // 数据: 0，优先级: 0
        p_queue_send(pq, &data3, 3);  // 数据: 3，优先级: 1
    }

    p_queue_print(pq);  // 打印队列
    p_queue_info_log(TAG, "Total elements in all queues: %d", pq->total_size);

    int *popped_data[100];
    int totol_size = p_queue_get_total_size(pq);
    for (int i = 0; i < totol_size; i++)
    {
        p_queue_receive(pq, (void **)&popped_data[i]);
    }
    p_queue_info_log(TAG, "Receive data: ");
    for (int i = 0; i < totol_size; i++)
    {
        printf("%d ", *popped_data[i]);  // 删除堆顶元素并打印
    }
    printf("\n");

    p_queue_print(pq);  // 打印队列

    p_queue_destroy(&pq);

    return 0;
}